package com.ruoyi.qywx.callback.events;

import com.ruoyi.common.core.cache.Meta;
import com.ruoyi.qywx.callback.txl.ExternalUserEncrypt;
import com.ruoyi.qywx.enums.SyncExtUserEm;
import com.ruoyi.qywx.service.inters.SyncQiyeService;

/**
 * @author : hcl
 * @Date : 2023/8/21 14:02
 * 添加客户事件
 */
public class ExternalUserEvent extends QywxEvent<ExternalUserEncrypt> {
    private final SyncExtUserEm type;

    public ExternalUserEvent(SyncQiyeService syncService, ExternalUserEncrypt encrypt, Meta meta) {
        super(syncService, encrypt, meta);
        this.type = SyncExtUserEm.valueOf(encrypt.getChangeType().toUpperCase());
    }

    @Override
    public void eventExecute() {
        ExternalUserEncrypt event = getEncrypt();
        switch (type) {
            case ADD_EXTERNAL_CONTACT:
                this.getSyncService().addExternalContact(event, getMeta());
                break;
            case EDIT_EXTERNAL_CONTACT:
                this.getSyncService().editExternalContact(event, getMeta());
                break;
            case ADD_HALF_EXTERNAL_CONTACT:
                break;
            case DEL_EXTERNAL_CONTACT:
                this.getSyncService().delExternalContact(event, getMeta().getTeamId());
                break;
            case DEL_FOLLOW_USER:
                this.getSyncService().delFollower(event, getMeta().getTeamId());
                break;
            case TRANSFER_FAIL:
                break;
        }
    }
}
